
import { ref } from 'vue'
import { defineStore } from 'pinia'

export const useAuthStore = defineStore('auth', () => {
  const token = ref('')
  const userInfo = ref({
    customerNo: '520523015641', // 龙凤
    // customerNo: '520529015466' // 红林
  })

  const globalParams = ref({
    customerNo: userInfo.value.customerNo,
    clientId: '123456789',
    startTime: '',
    endTime: '',
    areaId: '',
    areaName: '',
    alarmId: '',
    cdCode: ''
  })

  function setToken(token: string) {
    token.value = token
  }

  function setUserInfo(userInfo: any) {
    userInfo.value = userInfo
  }

  function clearToken() {
    token.value = ''
  }

  function clearUserInfo() {
    userInfo.value = {}
  }

  function getToken() {
    return token.value
  }

  function getUserInfo() {
    return userInfo.value
  }

  function setGlobalParamsItem(key: keyof typeof globalParams.value, value: string) {
    globalParams.value[key] = value
  }

  const modeParams = ref({
    menu: '0', // 0 - 区域，1 - 人员，2 - 视频，3 - 传感器，4 - 报警
    model: 'realtime', // realtime backtracking
  })
  function getModeParams() {
    return modeParams.value
  }
  function setModeParamsItem(key: keyof typeof modeParams.value, value: string) {
    modeParams.value[key] = value
  }

  const historyParams = ref({
    startTime: '', // 报警来源
    endTime: '', // 报警类型
  })

  function setHistoryParams(value: any) {
    historyParams.value = value
  }
  const historyData = ref({
    personList: [],
    videoList: [],
    sensorList: [],
    alarmList: [],
  })
  function setHistoryData(data: any) {
    historyData.value = data
  }
  function getHistoryData() {
    return historyData.value
  }

  const sceneTypeList = ref([])

  function setSceneTypeList(data: any) {
    sceneTypeList.value = data
  }
  function getSceneTypeList() {
    return sceneTypeList.value
  }

  return {
    token,
    userInfo,
    setToken,
    setUserInfo,
    clearToken,
    clearUserInfo,
    getToken,
    getUserInfo,
    globalParams,
    setGlobalParamsItem,
    modeParams,
    getModeParams,
    setModeParamsItem,
    historyData,
    setHistoryData,
    getHistoryData,
    historyParams,
    setHistoryParams,
    sceneTypeList,
    setSceneTypeList,
    getSceneTypeList,
  }
})

